package csc.fresher.finalgroupfour.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import csc.fresher.finalgroupfour.dao.CustomerDAO;
import csc.fresher.finalgroupfour.domain.Account;
import csc.fresher.finalgroupfour.domain.Customer;
import csc.fresher.finalgroupfour.domain.User;

@Service
public class CustomerService {
	@Autowired
	private CustomerDAO customerDAO;
	
	public void addCustomer(Customer customer) {
		customerDAO.addCustomer(customer);
	}

	public List<Customer> listCustomers() {
		return customerDAO.listCustomers();
	}
	
	public List<Customer> listAvailableCustomers() {
		return customerDAO.listAvailableCustomers();
	}

	public void updateCustomer(Customer customer) {
		customerDAO.updateCustomer(customer);
	}

	public void deleteCustomer(Customer customer) {
		customerDAO.deleteCustomer(customer);
	}

	public Customer findCustomer(String customerCardNumberId) {
		return customerDAO.findCustomer(customerCardNumberId);
	}
	
	public Customer findCustomerByUser(User user) {
		List<Account> accountList = (List<Account>) user.getAccounts();
		return accountList.get(0).getCustomer();
	}
}
